package ninthDay;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class IsPalindrome {
    public boolean isPalindrome(ListNode head) {
        if (head.next == null){
            return true;
        }
        Stack<Integer> stack = new Stack<>();
        ListNode temp = head;
        while (temp.next != null){
            stack.push(temp.val);
            temp = temp.next;
        }
        stack.push(temp.val);
        while (head != null){
            Integer pop = stack.pop();
            if (!pop.equals(head.val)){
                return false;
            }
            head = head.next;
        }
        return true;
    }
}
